package com.co0964;

import java.sql.SQLException;
import java.util.List;

import com.co0964.bean.Category;
import com.co0964.bean.Product;
import com.co0964.fetcher.CategoryFetcher;
import com.co0964.fetcher.ProductFetcher;
import com.co0964.util.Configuration;
import com.co0964.util.JdbcUtil;

public class Main {
	
	public static String COOKIE = "CUK45=cuk45_sw0962_bcfa9467144d46d4c0a44fc6708068e7; CUK2Y=cuk45_sw0962_bcfa9467144d46d4c0a44fc6708068e7; PHPSESSID=a612e378cd8192ca2cd8ee147a0128de; SESSION_CHECK=Y; bigdata_log=1; recent_plist=6144%7C6410%7C6455%7C3615%7C6622%7C6581%7C6127%7C6500%7C6456%7C6631%7C7176%7C7184; iscache=F; ec_mem_level=4; iLastSec=27; isviewtype=pc";
	
	public static void main(String[] args) throws SQLException {
		Configuration.load();
		JdbcUtil.init();
		
		DataAccess dataAccess = new DataAccess();
		
		
//		CategoryFetcher cf = new CategoryFetcher();
//		List<Category>  categories = cf.fetch();
//		dataAccess.insertCategory(categories);
		
		List<Category> categories = dataAccess.queryCategory();
		for(int i=0; i<categories.size(); i++){
			try{
				System.out.println("category : " + (i+1) + " / " + categories.size());
				Category category = categories.get(i);
				ProductFetcher pf = new ProductFetcher(category.getCid());
				List<Product> products = pf.fetch();
				dataAccess.insertProduct(products);
			}catch (Exception e) {
				e.printStackTrace();
			}
		}
		
	}
}
